<template>
    <div>

        <el-card>
            <div class="table">
                <el-table :data="tableData" strip>

                    <el-table-column type="index" label="序号" align="center" sortable></el-table-column>
                    <el-table-column prop="shopName" label="名称"></el-table-column>
                    <el-table-column prop="img" label="资质证书" align="center">
                        <template v-slot="scope">
                            <div style="display: flex;justify-content: center; align-items: center">
                                <el-image style="width: 40px; height: 40px; border-radius: 50%"
                                    v-if="scope.row.qualificationFile" :src="scope.row.qualificationFile"
                                    :preview-src-list="[scope.row.qualificationFile]"></el-image>
                            </div>
                        </template>

                    </el-table-column>
                    <el-table-column prop="img" label="身份证" align="center">
                        <template v-slot="scope">
                            <div style="display: flex;justify-content: center; align-items: center">
                                <el-image style="width: 40px; height: 40px; border-radius: 50%"
                                    v-if="scope.row.identityFile" :src="scope.row.identityFile"
                                    :preview-src-list="[scope.row.identityFile]"></el-image>
                            </div>
                        </template>

                    </el-table-column>

                    <el-table-column prop="identityNum" label="身份证号"></el-table-column>
                    <el-table-column prop="status" label="状态">
                        <template v-slot="scope">

                            <el-tag v-if="scope.row.status == '待审核'" type="success">{{ scope.row.status }}</el-tag>
                            <el-tag v-if="scope.row.status == '通过'" type="success">{{ scope.row.status }}</el-tag>
                            <el-tag v-if="scope.row.status == '驳回'" type="danger">{{ scope.row.status }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="remark" label="审核意见"></el-table-column>
                    <el-table-column label="操作" align="center" width="240" fixed="right">
                        <template v-slot="scope">
                            <el-button v-if="scope.row.status
                                == '待审核'" size="mini" type="primary" plain @click="add(scope.row)">审核</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div class="pagination" style="margin-top: 10px;">
                    <el-pagination background @current-change="handleCurrentChange" :current-page="queryform.pageNum"
                        :page-sizes="[5, 10, 20]" :page-size="queryform.pageSize" layout="total, prev, pager, next"
                        :total="total">
                    </el-pagination>
                </div>
            </div>

        </el-card>
        <el-dialog title="审核" :visible.sync="fromVisible" width="40%" :close-on-click-modal="false" destroy-on-close>
            <el-form :model="form" label-width="100px" style="padding-right: 50px" :rules="rules" ref="formRef">
                <el-form-item label="审核结果" prop="status" required>
                    <el-select v-model="form.status" placeholder="审核结果" style="width: 100%;">
                        <el-option label="通过" value="通过"></el-option>
                        <el-option label="驳回" value="驳回"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="描述" prop="remark">
                    <el-input type="textarea" v-model="form.remark" placeholder="请输入描述"></el-input>
                </el-form-item>
            </el-form>

            <div slot="footer" class="dialog-footer">
                <el-button @click="fromVisible = false">取 消</el-button>
                <el-button type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import service from '@/request';

export default {
    data() {
        return {
            tableData: [],  // 所有的数据
            pageNum: 1,   // 当前的页码
            pageSize: 10,  // 每页显示的个数
            total: 0,
            username: null,
            img: "",
            token: "",
            typelist: [],
            fileList: [],
            name: null,
            uploadHeaders: {

                Authorization: window.localStorage.getItem("token")
            },

            fromVisible: false,
            avatar: "",
            queryform: {
                keyword: "",
                pageNum: 1,
                pageSize: 10
            },
            license: "",
            form: {
                img: "",

            },
            user: {},
            rules: {

                // business_id: [
                //     { required: true, message: '请选择商家类型', trigger: 'blur' },
                // ]
            },
            ids: [],
            sjlist: [],
        }
    },
    mounted() {
        this.token = window.localStorage.getItem("token")
        this.user = JSON.parse(window.localStorage.getItem("userinfo"))
        console.log(this.user)

        this.getlist()
        this.getall()
    },
    methods: {
        addorxiaj(row) {
            this.$confirm('是否确认上下架?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                const res = await service.get("/info/uporoff?id=" + row.id);
                this.getlist()
            })
        },
        async getall() {
            const res = await service.get("/type/all");
            console.log(res)
            this.typelist = res.data
        },


        del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                const res = await service.get("/info/delete?id=" + id)
                console.log(res)
                if (res.code == 200) {
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                    this.getlist()
                }

            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
        force(e) {
            this.form.timeRange = e;
            this.$forceUpdate();
        },
        handleEdit(row) {
            this.form = row;
            this.img = row.img;


            this.fromVisible = true
        },
        search() {
            this.queryform.pageNum = 1;
            this.queryform.pageSize = 10;
            this.getlist()
        },
        research() {
            this.queryform.keyword = ""
            this.queryform.pageNum = 1;
            this.queryform.pageSize = 10;
            this.getlist()

        },
        async getlist() {
            // if (this.user.role == 'HOTEL') {
            //     this.queryform.hotelId = this.user.id

            // }else{
            //     this.queryform.hotelId = ""

            // }
            const res = await service.get("/examine/list", { params: this.queryform });
            console.log(res);
            if (res.code == 200) {
                this.tableData = res.data.records;
                this.total = res.data.total;
            }


        },
        add(row) {
            this.img = ""
            this.form = {}
            this.form.id = row.id
            this.form.shopId = row.shopId;
            this.fromVisible = true

        },
        handleLicenseSuccess(e) {

        },
        async save() {
            if (!this.form.status) {
                return this.$message.warning("请选择审核结果")
            }


            const res = await service.get("/examine/certify", { params: this.form });
            if (res.code == 200) {
                this.fromVisible = false
                this.$message.success("操作成功")
                this.getlist()
            }





        },
        handleCurrentChange(e) {

        },
        handleAvatarSuccess(e) {
            console.log(e)

            this.form.icon = e.data;
            this.$forceUpdate()
            // this.fileList.push({

            // })

        },

    }
}
</script>
<style scoped>
.mb {
    margin-bottom: 10px;
}
</style>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409EFF;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px !important;
    text-align: center;
}

.avatar {
    width: 178px;
    height: 178px;
    display: block;
}
</style>